using System;
using System.ComponentModel;
using System.Threading;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.Interfaces;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.Respondents;

namespace FU.Capstones.IMS.Web.Common.InventoryServiceProxy.OperationContracts
{
    public partial class InventoryServiceClient
    {

        #region GetOrderCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Order>> GetOrderCollectionCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginGetOrderCollection(bool isShowAll, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginGetOrderCollection(isShowAll, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Order> IInventoryService.EndGetOrderCollection(IAsyncResult result)
        {
            return Channel.EndGetOrderCollection(result);
        }

        private IAsyncResult OnBeginGetOrderCollection(object[] inValues, AsyncCallback callback, object asyncState)
        {
            bool isShowAll = (bool)inValues[0];

            return ((IInventoryService)(this)).BeginGetOrderCollection(isShowAll, callback, asyncState);
        }

        private object[] OnEndGetOrderCollection(IAsyncResult result)
        {
            CollectionFeedback<Order> retVal = ((IInventoryService)(this)).EndGetOrderCollection(result);
            return new object[] { retVal };
        }

        private void OnGetOrderCollectionCompleted(object state)
        {
            if ((GetOrderCollectionCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                GetOrderCollectionCompleted(this, new CollectionFeedbackCompletedEventArgs<Order>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetOrderCollectionAsync(bool isShowAll)
        {
            GetOrderCollectionAsync(isShowAll, null);
        }

        public void GetOrderCollectionAsync(bool isShowAll, object userState)
        {
            if ((onBeginGetOrderCollectionDelegate == null))
            {
                onBeginGetOrderCollectionDelegate = new BeginOperationDelegate(OnBeginGetOrderCollection);
            }
            if ((onEndGetOrderCollectionDelegate == null))
            {
                onEndGetOrderCollectionDelegate = new EndOperationDelegate(OnEndGetOrderCollection);
            }
            if ((onGetOrderCollectionCompletedDelegate == null))
            {
                onGetOrderCollectionCompletedDelegate = new SendOrPostCallback(OnGetOrderCollectionCompleted);
            }
            InvokeAsync(onBeginGetOrderCollectionDelegate, new object[] {
                    isShowAll}, onEndGetOrderCollectionDelegate, onGetOrderCollectionCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetOrderCollectionDelegate;

        private EndOperationDelegate onEndGetOrderCollectionDelegate;

        private SendOrPostCallback onGetOrderCollectionCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginGetOrderCollection(bool isShowAll, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = isShowAll;

                IAsyncResult _result = BeginInvoke("GetOrderCollection", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Order> EndGetOrderCollection(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Order> _result = ((CollectionFeedback<Order>)(EndInvoke("GetOrderCollection", _args, result)));
                return _result;
            }
        }

        #endregion
        
        #region GetSingleOrder

        public event EventHandler<SingleFeedbackCompletedEventArgs<Order>> GetSingleOrderCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginGetSingleOrder(int orderID, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginGetSingleOrder(orderID, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<Order> IInventoryService.EndGetSingleOrder(IAsyncResult result)
        {
            return Channel.EndGetSingleOrder(result);
        }

        private IAsyncResult OnBeginGetSingleOrder(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int orderID = (int)inValues[0];

            return ((IInventoryService)(this)).BeginGetSingleOrder(orderID, callback, asyncState);
        }

        private object[] OnEndGetSingleOrder(IAsyncResult result)
        {
            SingleFeedback<Order> retVal = ((IInventoryService)(this)).EndGetSingleOrder(result);
            return new object[] { retVal };
        }

        private void OnGetSingleOrderCompleted(object state)
        {
            if ((GetSingleOrderCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                GetSingleOrderCompleted(this, new SingleFeedbackCompletedEventArgs<Order>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetSingleOrderAsync(int orderID)
        {
            GetSingleOrderAsync(orderID, null);
        }

        public void GetSingleOrderAsync(int orderID, object userState)
        {
            if ((onBeginGetSingleOrderDelegate == null))
            {
                onBeginGetSingleOrderDelegate = new BeginOperationDelegate(OnBeginGetSingleOrder);
            }
            if ((onEndGetSingleOrderDelegate == null))
            {
                onEndGetSingleOrderDelegate = new EndOperationDelegate(OnEndGetSingleOrder);
            }
            if ((onGetSingleOrderCompletedDelegate == null))
            {
                onGetSingleOrderCompletedDelegate = new SendOrPostCallback(OnGetSingleOrderCompleted);
            }
            InvokeAsync(onBeginGetSingleOrderDelegate, new object[] {
                                                                                orderID}, onEndGetSingleOrderDelegate, onGetSingleOrderCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetSingleOrderDelegate;

        private EndOperationDelegate onEndGetSingleOrderDelegate;

        private SendOrPostCallback onGetSingleOrderCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginGetSingleOrder(int orderID, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = orderID;

                IAsyncResult _result = BeginInvoke("GetSingleOrder", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<Order> EndGetSingleOrder(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<Order> _result = ((SingleFeedback<Order>)(EndInvoke("GetSingleOrder", _args, result)));
                return _result;
            }
        }

        #endregion

        #region InsertOrder

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertOrderCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginInsertOrder(Order data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginInsertOrder(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<int> IInventoryService.EndInsertOrder(IAsyncResult result)
        {
            return Channel.EndInsertOrder(result);
        }

        private IAsyncResult OnBeginInsertOrder(object[] inValues, AsyncCallback callback, object asyncState)
        {
            Order data = (Order)inValues[0];

            return ((IInventoryService)(this)).BeginInsertOrder(data, callback, asyncState);
        }

        private object[] OnEndInsertOrder(IAsyncResult result)
        {
            SingleFeedback<int> retVal = ((IInventoryService)(this)).EndInsertOrder(result);
            return new object[] { retVal };
        }

        private void OnInsertOrderCompleted(object state)
        {
            if ((InsertOrderCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                InsertOrderCompleted(this, new SingleFeedbackCompletedEventArgs<int>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void InsertOrderAsync(Order data)
        {
            InsertOrderAsync(data, null);
        }

        public void InsertOrderAsync(Order data, object userState)
        {
            if ((onBeginInsertOrderDelegate == null))
            {
                onBeginInsertOrderDelegate = new BeginOperationDelegate(OnBeginInsertOrder);
            }
            if ((onEndInsertOrderDelegate == null))
            {
                onEndInsertOrderDelegate = new EndOperationDelegate(OnEndInsertOrder);
            }
            if ((onInsertOrderCompletedDelegate == null))
            {
                onInsertOrderCompletedDelegate = new SendOrPostCallback(OnInsertOrderCompleted);
            }
            InvokeAsync(onBeginInsertOrderDelegate, new object[] {
                                                                             data}, onEndInsertOrderDelegate, onInsertOrderCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginInsertOrderDelegate;

        private EndOperationDelegate onEndInsertOrderDelegate;

        private SendOrPostCallback onInsertOrderCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginInsertOrder(Order data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("InsertOrder", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<int> EndInsertOrder(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<int> _result = ((SingleFeedback<int>)(EndInvoke("InsertOrder", _args, result)));
                return _result;
            }
        }

        #endregion

        #region UpdateOrder

        public event EventHandler<FeedbackCompletedEventArgs> UpdateOrderCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginUpdateOrder(Order data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginUpdateOrder(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        Feedback IInventoryService.EndUpdateOrder(IAsyncResult result)
        {
            return Channel.EndUpdateOrder(result);
        }

        private IAsyncResult OnBeginUpdateOrder(object[] inValues, AsyncCallback callback, object asyncState)
        {
            Order data = (Order)inValues[0];

            return ((IInventoryService)(this)).BeginUpdateOrder(data, callback, asyncState);
        }

        private object[] OnEndUpdateOrder(IAsyncResult result)
        {
            Feedback retVal = ((IInventoryService)(this)).EndUpdateOrder(result);
            return new object[] { retVal };
        }

        private void OnUpdateOrderCompleted(object state)
        {
            if ((UpdateOrderCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                UpdateOrderCompleted(this, new FeedbackCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void UpdateOrderAsync(Order data)
        {
            UpdateOrderAsync(data, null);
        }

        public void UpdateOrderAsync(Order data, object userState)
        {
            if ((onBeginUpdateOrderDelegate == null))
            {
                onBeginUpdateOrderDelegate = new BeginOperationDelegate(OnBeginUpdateOrder);
            }
            if ((onEndUpdateOrderDelegate == null))
            {
                onEndUpdateOrderDelegate = new EndOperationDelegate(OnEndUpdateOrder);
            }
            if ((onUpdateOrderCompletedDelegate == null))
            {
                onUpdateOrderCompletedDelegate = new SendOrPostCallback(OnUpdateOrderCompleted);
            }
            InvokeAsync(onBeginUpdateOrderDelegate, new object[] {
                                                                             data}, onEndUpdateOrderDelegate, onUpdateOrderCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginUpdateOrderDelegate;

        private EndOperationDelegate onEndUpdateOrderDelegate;

        private SendOrPostCallback onUpdateOrderCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginUpdateOrder(Order data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("UpdateOrder", _args, callback, asyncState);
                return _result;
            }

            public Feedback EndUpdateOrder(IAsyncResult result)
            {
                object[] _args = new object[0];
                Feedback _result = ((Feedback)(EndInvoke("UpdateOrder", _args, result)));
                return _result;
            }
        }

        #endregion

        #region DeleteOrder

        public event EventHandler<FeedbackCompletedEventArgs> DeleteOrderCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginDeleteOrder(int data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginDeleteOrder(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        Feedback IInventoryService.EndDeleteOrder(IAsyncResult result)
        {
            return Channel.EndDeleteOrder(result);
        }

        private IAsyncResult OnBeginDeleteOrder(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int data = (int)inValues[0];

            return ((IInventoryService)(this)).BeginDeleteOrder(data, callback, asyncState);
        }

        private object[] OnEndDeleteOrder(IAsyncResult result)
        {
            Feedback retVal = ((IInventoryService)(this)).EndDeleteOrder(result);
            return new object[] { retVal };
        }

        private void OnDeleteOrderCompleted(object state)
        {
            if ((DeleteOrderCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                DeleteOrderCompleted(this, new FeedbackCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void DeleteOrderAsync(int data)
        {
            DeleteOrderAsync(data, null);
        }

        public void DeleteOrderAsync(int data, object userState)
        {
            if ((onBeginDeleteOrderDelegate == null))
            {
                onBeginDeleteOrderDelegate = new BeginOperationDelegate(OnBeginDeleteOrder);
            }
            if ((onEndDeleteOrderDelegate == null))
            {
                onEndDeleteOrderDelegate = new EndOperationDelegate(OnEndDeleteOrder);
            }
            if ((onDeleteOrderCompletedDelegate == null))
            {
                onDeleteOrderCompletedDelegate = new SendOrPostCallback(OnDeleteOrderCompleted);
            }
            InvokeAsync(onBeginDeleteOrderDelegate, new object[] {
                                                                             data}, onEndDeleteOrderDelegate, onDeleteOrderCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginDeleteOrderDelegate;

        private EndOperationDelegate onEndDeleteOrderDelegate;

        private SendOrPostCallback onDeleteOrderCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginDeleteOrder(int data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("DeleteOrder", _args, callback, asyncState);
                return _result;
            }

            public Feedback EndDeleteOrder(IAsyncResult result)
            {
                object[] _args = new object[0];
                Feedback _result = ((Feedback)(EndInvoke("DeleteOrder", _args, result)));
                return _result;
            }
        }

        #endregion

        #region SearchOrder

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Order>> SearchOrderCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginSearchOrder(OrderCriteria criteria, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginSearchOrder(criteria, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Order> IInventoryService.EndSearchOrder(IAsyncResult result)
        {
            return Channel.EndSearchOrder(result);
        }

        private IAsyncResult OnBeginSearchOrder(object[] inValues, AsyncCallback callback, object asyncState)
        {
            OrderCriteria criteria = (OrderCriteria)inValues[0];

            return ((IInventoryService)(this)).BeginSearchOrder(criteria, callback, asyncState);
        }

        private object[] OnEndSearchOrder(IAsyncResult result)
        {
            CollectionFeedback<Order> retVal = ((IInventoryService)(this)).EndSearchOrder(result);
            return new object[] { retVal };
        }

        private void OnSearchOrderCompleted(object state)
        {
            if ((SearchOrderCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                SearchOrderCompleted(this, new CollectionFeedbackCompletedEventArgs<Order>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void SearchOrderAsync(OrderCriteria criteria)
        {
            SearchOrderAsync(criteria, null);
        }

        public void SearchOrderAsync(OrderCriteria criteria, object userState)
        {
            if ((onBeginSearchOrderDelegate == null))
            {
                onBeginSearchOrderDelegate = new BeginOperationDelegate(OnBeginSearchOrder);
            }
            if ((onEndSearchOrderDelegate == null))
            {
                onEndSearchOrderDelegate = new EndOperationDelegate(OnEndSearchOrder);
            }
            if ((onSearchOrderCompletedDelegate == null))
            {
                onSearchOrderCompletedDelegate = new SendOrPostCallback(OnSearchOrderCompleted);
            }
            InvokeAsync(onBeginSearchOrderDelegate, new object[] {
                                                                             criteria}, onEndSearchOrderDelegate, onSearchOrderCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginSearchOrderDelegate;

        private EndOperationDelegate onEndSearchOrderDelegate;

        private SendOrPostCallback onSearchOrderCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginSearchOrder(OrderCriteria criteria, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = criteria;

                IAsyncResult _result = BeginInvoke("SearchOrder", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Order> EndSearchOrder(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Order> _result = ((CollectionFeedback<Order>)(EndInvoke("SearchOrder", _args, result)));
                return _result;
            }
        }

        #endregion


        #region GetOrderCollectionByParameter

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Order>> GetOrderCollectionByParameterCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginGetOrderCollectionByParameter(bool? isMaterial, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginGetOrderCollectionByParameter(isMaterial, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Order> IInventoryService.EndGetOrderCollectionByParameter(IAsyncResult result)
        {
            return Channel.EndGetOrderCollectionByParameter(result);
        }

        private IAsyncResult OnBeginGetOrderCollectionByParameter(object[] inValues, AsyncCallback callback, object asyncState)
        {
            bool? isMaterial = (bool?)inValues[0];

            return ((IInventoryService)(this)).BeginGetOrderCollectionByParameter(isMaterial, callback, asyncState);
        }

        private object[] OnEndGetOrderCollectionByParameter(IAsyncResult result)
        {
            CollectionFeedback<Order> retVal = ((IInventoryService)(this)).EndGetOrderCollectionByParameter(result);
            return new object[] { retVal };
        }

        private void OnGetOrderCollectionByParameterCompleted(object state)
        {
            if ((GetOrderCollectionByParameterCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                GetOrderCollectionByParameterCompleted(this, new CollectionFeedbackCompletedEventArgs<Order>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetOrderCollectionByParameterAsync(bool? isMaterial)
        {
            GetOrderCollectionByParameterAsync(isMaterial, null);
        }

        public void GetOrderCollectionByParameterAsync(bool? isMaterial, object userState)
        {
            if ((onBeginGetOrderCollectionByParameterDelegate == null))
            {
                onBeginGetOrderCollectionByParameterDelegate = new BeginOperationDelegate(OnBeginGetOrderCollectionByParameter);
            }
            if ((onEndGetOrderCollectionByParameterDelegate == null))
            {
                onEndGetOrderCollectionByParameterDelegate = new EndOperationDelegate(OnEndGetOrderCollectionByParameter);
            }
            if ((onGetOrderCollectionByParameterCompletedDelegate == null))
            {
                onGetOrderCollectionByParameterCompletedDelegate = new SendOrPostCallback(OnGetOrderCollectionByParameterCompleted);
            }
            InvokeAsync(onBeginGetOrderCollectionByParameterDelegate, new object[] {
                    isMaterial}, onEndGetOrderCollectionByParameterDelegate, onGetOrderCollectionByParameterCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetOrderCollectionByParameterDelegate;

        private EndOperationDelegate onEndGetOrderCollectionByParameterDelegate;

        private SendOrPostCallback onGetOrderCollectionByParameterCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginGetOrderCollectionByParameter(bool? isMaterial, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = isMaterial;

                IAsyncResult _result = BeginInvoke("GetOrderCollectionByParameter", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Order> EndGetOrderCollectionByParameter(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Order> _result = ((CollectionFeedback<Order>)(EndInvoke("GetOrderCollectionByParameter", _args, result)));
                return _result;
            }
        }

        #endregion
        

    }
}
